package org.jheuristics.ga.operators;

import org.epanetgrid.otimizacao.log.AGLogger;
import org.jheuristics.Individual;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.GAStatus;
import org.jheuristics.ga.Population;


public class SelectionClearingOperatorLogged extends SelectionClearingOperator {

	private String tipoDeSelecao;

	/**
	 * TODO
	 *
	 * @param rate
	 * @param selector
	 * @param fromPopChooser
	 * @param cleanAfterFromPop
	 * @param toPopChooser
	 * @param cleanBeforeToPop
	 */
	public SelectionClearingOperatorLogged(Rate rate, Selector selector, 
			PopulationChooser fromPopChooser, boolean cleanAfterFromPop, PopulationChooser toPopChooser, boolean cleanBeforeToPop, 
			String tipoDeSelecao) {
		super(rate, selector, fromPopChooser, cleanAfterFromPop, toPopChooser, cleanBeforeToPop);
		this.tipoDeSelecao = tipoDeSelecao;
	}
	/**
	 * TODO
	 *
	 * @param rate
	 * @param selector
	 * @param fromPopChooser
	 * @param cleanAfterFromPop
	 * @param toPopChooser
	 * @param cleanBeforeToPop
	 */
	public SelectionClearingOperatorLogged(Rate rate, Selector selector, PopulationChooser fromPopChooser, ClosureSelection afterSelectionClosure, PopulationChooser toPopChooser, ClosureSelection beforeInsertionClosure) {
		super(rate, selector, fromPopChooser, afterSelectionClosure, toPopChooser, beforeInsertionClosure);
	}
	
	public SelectionClearingOperatorLogged(Rate rate, Selector selector, PopulationChooser fromPopChooser, ClosureSelection afterSelectionClosure, PopulationChooser toPopChooser, ClosureSelection beforeInsertionClosure, String tipo) {
		this(rate, selector, fromPopChooser, afterSelectionClosure, toPopChooser, beforeInsertionClosure);
		this.tipoDeSelecao = tipo;
	}

	@Override
	protected Population select(Population population, GAStatus status, GAConfig config) {
		
		StringBuffer buffer = new StringBuffer("\nSelecionando individ�duos "+tipoDeSelecao+":\n");
		
		Population selected = super.select(population, status, config);
		
		for (Individual ind : selected.toIndividualArray()) {
			buffer.append(ind);
			buffer.append("\n");
		}
		
		AGLogger.getInstance().debug(buffer);
		return selected;
	}
	
}
